package com.example.magictowerx;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;

public class SplashScreen extends GameView
{
    private int			tick		= 0;
    private Paint		paint		= null;
    private MainGame	mMainGame	= null;


    public SplashScreen(Context context, MainGame mainGame)
    {
        super(context);
        paint = new Paint();
        mMainGame = mainGame;
        paint.setTextSize(MySet.TextSize);
        paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    }


    protected void onDraw(Canvas canvas)
    {
        tick++;
        paint.setColor(Color.BLACK);
        MySet.fillRect(canvas, 0, 0, MySet.SCREENW, MySet.SCREENH, paint);

        paint.setColor(Color.WHITE);
        String string = "是否开启音效？";
        MySet.drawString(canvas, string, (MySet.SCREENW - paint.measureText(string)) / 2, (MySet.SCREENH - paint.getTextSize()) / 2, paint);
        string = "是";
        MySet.drawString(canvas, string, 350, MySet.SCREENH - paint.getTextSize() - 550, paint);
        string = "否";
        MySet.drawString(canvas, string, MySet.SCREENW - paint.measureText(string) - 350, MySet.SCREENH - paint.getTextSize() - 550, paint);
    }


    public boolean onTouchEvent(MotionEvent event)
    {
        int x = (int) event.getX();
        int y = (int) event.getY();
        int type = 0;
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // 记录触摸点坐标
                if (MySet.touchYes(x,y) )
                {
                    mMainGame.mbMusic = 1;;
                }

                else if (MySet.touchNo(x,y))
                {
                    mMainGame.mbMusic = 0;
                }
                mMainGame.controlView(MySet.GAME_MENU);
                if (mMainGame.mbMusic == 1)
                {
                    mMainGame.mCMIDIPlayer.PlayMusic(1);
                }
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return true;
    }

    public boolean onKeyUp(int keyCode)
    {
        if (keyCode == MySet.KEY_DPAD_OK)
        {
            mMainGame.mbMusic = 1;
        }
        mMainGame.controlView(MySet.GAME_MENU);
        if (mMainGame.mbMusic == 1)
        {
            mMainGame.mCMIDIPlayer.PlayMusic(1);
        }
        return true;
    }


    public boolean onKeyDown(int keyCode)
    {
        return true;
    }


    public void refurbish()
    {
        // if (tick > 10)
        // {
        // mMainGame.controlView(MySet.GAME_MENU);
        // }
    }


    public void reCycle()
    {
        paint = null;
        System.gc();
    }
}

